package indi.zhifa.study2025.oa.admin.facade.dep.impl;

import indi.zhifa.engine.core.common.utils.DtoEntityUtil;
import indi.zhifa.engine.mpenhance.utils.DbDtoEntityUtil;
import indi.zhifa.study2025.oa.admin.facade.dep.IPositionTagFacade;
import indi.zhifa.study2025.oa.dao.po.GenPositionTagEntity;
import indi.zhifa.study2025.oa.model.expose.dep.dto.PositionTagCreateDto;
import indi.zhifa.study2025.oa.model.expose.dep.dto.PositionTagEditDto;
import indi.zhifa.study2025.oa.model.expose.dep.vo.PositionTagVo;
import indi.zhifa.study2025.oa.service.dep.IPositionTagService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@RequiredArgsConstructor
@Component
public class PositionTagFacadeImpl implements IPositionTagFacade {

    final IPositionTagService mPositionTagService;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public PositionTagVo create(PositionTagCreateDto pPositionTagCreateDto) {
        GenPositionTagEntity positionTagEntity = DbDtoEntityUtil.createFromDto(pPositionTagCreateDto, GenPositionTagEntity.class);
        positionTagEntity = mPositionTagService.create(positionTagEntity);
        PositionTagVo rtn = DtoEntityUtil.trans(positionTagEntity, PositionTagVo.class);
        return rtn;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public PositionTagVo edit(Long pId, PositionTagEditDto pPositionTagEditDto) {
        GenPositionTagEntity positionTagEntity = mPositionTagService.edit(pId,pPositionTagEditDto);
        PositionTagVo rtn = DtoEntityUtil.trans(positionTagEntity, PositionTagVo.class);
        return rtn;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public PositionTagVo delete(Long pId) {
        GenPositionTagEntity positionTagEntity = mPositionTagService.delete(pId);
        PositionTagVo rtn = DtoEntityUtil.trans(positionTagEntity, PositionTagVo.class);
        return rtn;
    }

    @Override
    public PositionTagVo info(Long pId) {
        GenPositionTagEntity positionTagEntity = mPositionTagService.check(pId);
        PositionTagVo rtn = DtoEntityUtil.trans(positionTagEntity, PositionTagVo.class);
        return rtn;
    }

    @Override
    public List<PositionTagVo> list() {
        List<GenPositionTagEntity> positionTagEntityList = mPositionTagService.list();
        List<PositionTagVo> rtn = DtoEntityUtil.trans(positionTagEntityList, PositionTagVo.class);
        return rtn;
    }
}
